feat(client): add initial access token support for Dynamic Client Registration#1874
Conversation
…istration Add optional `dcrRegistrationAccessToken()` method to `OAuthClientProvider` interface, enabling OAuth 2.0 Dynamic Client Registration with initial access tokens per RFC 7591 Section 3. When the authorization server requires pre-authorisation for client registration, providers can implement this method to supply a Bearer token that is included in the DCR request. When not implemented, open registration continues as before (fully backward compatible). The token resolution is kept in the provider (not the SDK) as it is per-authorisation-server, following maintainer guidance from modelcontextprotocol#773. Closes modelcontextprotocol#772
|
@modelcontextprotocol/client
@modelcontextprotocol/server
@modelcontextprotocol/express
@modelcontextprotocol/fastify
@modelcontextprotocol/hono
@modelcontextprotocol/node
commit: |
|
hi @JosephDoUrden do you need this feature yourself? Could you describe the setup more clearly? The approach overall looks good, I just don't want to add it unless it's going to be used. We've since introduced CIMD support which is often a better fit than DCR altogether. |
Summary
Add support for OAuth 2.0 Dynamic Client Registration initial access tokens (RFC 7591 Section 3), enabling enterprise deployments that require pre-authorisation for client registration.
dcrRegistrationAccessToken()method toOAuthClientProviderinterfaceregisterClient()includes anAuthorization: Bearer <token>header in the DCR requestundefined, open registration continues as before (fully backward compatible)Closes #772
Design decisions
Following maintainer feedback from the previous attempt (#773):
OAuthClientProvider.auth.tsonly.OAuthClientProvideris the right place to resolve per-server tokens, consistent with how other credentials are handled.Changes
packages/client/src/client/auth.ts:dcrRegistrationAccessToken?()toOAuthClientProviderinterfaceinitialAccessTokenparameter toregisterClient()auth()flow to call the provider method and pass the token toregisterClient()packages/client/test/client/auth.test.ts:Authorizationheader inclusion when token is providedAuthorizationheader when token is absentTest plan
pnpm --filter @modelcontextprotocol/client test)pnpm build:all)pnpm typecheck:all)pnpm lint:all)AI Disclosure
AI assistance (Claude) was used for issue research, reviewing the previous PR feedback, and code exploration. The implementation was written and reviewed by the author.